package com.cnc.ssm.web;

import com.cnc.bas.util.Constants;
import com.cnc.bas.util.LTUtil;
import com.cnc.bas.web.BasMapForm;
import com.cnc.bas.web.SecureBaseDispatchAction;
import com.cnc.ssm.ISsmService;
import com.cnc.ssm.model.PwCodeType;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * User: Du bf
 * Date: 2004-11-29
 */

public class CodeTypeAction extends SecureBaseDispatchAction {
    private ISsmService ssmService = null;

    public void setServlet(ActionServlet actionServlet) {
        super.setServlet(actionServlet);
        ssmService = (ISsmService) this.getBean(Constants.BEAN_NAME_SSM);
    }

    public ActionForward list(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        HashMap hs = ((BasMapForm) form).getHs();
        List list = ssmService.listCodeType(hs);
        LTUtil.setPageData(request, list);
        return mapping.findForward("list");
    }

    public ActionForward create(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        return mapping.findForward("edit");
    }

    public ActionForward add(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response) throws Exception {
        ssmService.addCodeType(((CodeTypeForm) form).getCodeType());
        return mapping.findForward("edit");
    }

    public ActionForward edit(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        String codeType = request.getParameter("id");
        ((CodeTypeForm) form).setCodeType((PwCodeType) (ssmService.loadCodeType(codeType)));
        return mapping.findForward("edit");
    }

    public ActionForward update(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        ssmService.updateCodeType(((CodeTypeForm) form).getCodeType());
        return mapping.findForward("edit");
    }

    public ActionForward delete(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        String codeType = request.getParameter("id");
        ssmService.deleteCodeType(codeType);
        return mapping.findForward("list");
    }


}
